Skip to content

[Codex Security] Account-qualified search bypasses the new per-account proxy - #844

Closed
luvs01 wants to merge 1 commit into
devfrom
codex-security/arp_32e8908c5a852b51870b3ad5bddba5df
Closed

luvs01 wants to merge 1 commit into
devfrom
codex-security/arp_32e8908c5a852b51870b3ad5bddba5df

Conversation

@luvs01

@luvs01 luvs01 commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Search now uses the selected Codex account's configured outbound route.

  • The selected authentication context supplies the account ID to the established account-aware transport at the search sink.
  • Account egress overrides provider routing, preventing qualified pool credentials from escaping through global or direct transport.
  • Invalid or missing pool routes fail closed through the existing sanitized search error path without reaching the underlying fetch.
  • Existing authorization headers, account metadata isolation, bare-model projection, redirect policy, cancellation, and cleanup remain intact.
  • Verification was restricted to static source and diff evidence; runtime checks were not performed.

Static Verification Checks

  • Selected Account Egress (Passed) — src/server/search.ts handleSearch passes the selected auth-context account into codexAccountFetch, establishing account-bound egress at the sink.

  • Route Precedence Fails Closed (Passed) — src/codex/account-egress-runtime.ts codexAccountRouting prioritizes account egress over provider routing and rejects missing pool bindings.

  • Malformed Route Refusal (Passed) — tests/server/server-search.test.ts asserts malformed selected routes return 502 without invoking the outbound fetch stub.

  • Qualified Relay Compatibility (Passed) — tests/server/server-search.test.ts asserts successful qualified search preserves credentials, account headers, and bare upstream model projection.

  • Direct Caller Compatibility (Passed) — src/codex/account-egress-runtime.ts codexAccountRouting leaves direct and main callers unchanged, preserving existing relay behavior.

  • Static Diff Integrity (Passed) — git diff --check reports no whitespace errors across all changed files, establishing final patch integrity.

  • Finding: acf_b8f0e4ecf67276cb7603e32d7a0a3408

  • Patch: arp_32e8908c5a852b51870b3ad5bddba5df

  • Base commit: 5c827dc96b943b2d5433c6d74bfb1ecdc4b27502

  • Patch SHA-256: 4fb302c0c04999c34462ae5c9ede2e78e325fbd3f0beb86cb753b437971925bd


Devin Review

@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 26, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

Devin Review

Comment thread src/server/search.ts
try {
upstream.beforeDispatch?.();
upstreamResponse = await fetch(url, {
upstreamResponse = await codexAccountFetch(codexLogAccountId(upstream.authContext), { config })(url, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Local search proxy refusals can switch the active Codex account

When process NO_PROXY conflicts with a Pool account’s HTTP proxy, search records the local refusal as an upstream connection failure. Repeated unqualified searches can switch the active account even though no search reached ChatGPT.

Learn more

The ChatGPT search relay now uses codexAccountFetch for pool traffic. If process NO_PROXY exempts ChatGPT, configuredOutboundFetch rejects an explicitly selected HTTP proxy before opening a connection. The search error handler passes that refusal to the unqualified sidecar’s outcome recorder as connect_error. recordCodexUpstreamOutcome adds to the selected account’s transient failure streak and calls applyFailureFailover for an active account. With an eligible sibling, this updates the shared active selection rather than just returning a search error.

Example: With account A active, account B eligible, and the default threshold of three, three ordinary unqualified searches select A and hit the same local proxy refusal. The third failure can promote B, so fixing A’s proxy settings does not undo the account switch.

Recommended fix: Handle typed pre-send route refusals separately in handleSearch. Release the probe lease and return a local route error without recording an upstream outcome. Add a regression test for a valid HTTP proxy conflicting with process NO_PROXY that checks both zero sends and unchanged Pool health.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread src/server/search.ts
try {
upstream.beforeDispatch?.();
upstreamResponse = await fetch(url, {
upstreamResponse = await codexAccountFetch(codexLogAccountId(upstream.authContext), { config })(url, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 SOCKS5 searches fail before longer configured deadlines

Account-routed SOCKS5 searches inherit a 200-second idle timeout from socks5Fetch. A search that sends no headers during that interval returns 502 even when its configured deadline allows it to finish.

Learn more

The search handler creates an abort signal for the configured total deadline. Applying an account-specific SOCKS5 route makes configuredOutboundFetch use socks5Fetch, which also installs a fixed 200-second upstream socket idle timer. The search contract explains why a healthy request can send no response headers until the search finishes. If the socket timer fires first, it throws Socks5FetchError, not TimeoutError, and the search error handler returns 502 because the request deadline has not yet expired.

Example: With search.timeoutMs set to 240,000, a search that sends its first response headers 210 seconds after dispatch is cut off at 200 seconds when the selected account uses SOCKS5.

Recommended fix: Let this relay pass its upstream deadline policy through the account-aware transport, so the SOCKS5 response idle timer does not preempt the search budget. Keep the SOCKS5 connection and handshake guards and retain the fixed default for callers that do not supply a response budget.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +79 to +80
Search also resolves the selected Pool account's outbound route at its physical send boundary;
an account route overrides the OpenAI provider route, and an invalid route refuses the send.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Public proxy docs still exclude unqualified Pool search

Unqualified search now uses account-aware egress when it selects a Pool account. The provider configuration guide still says unqualified search has no provider route. Update it to distinguish Pool search from caller-owned search.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +336 to +345
globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => {
const headers = new Headers(init?.headers);
sends.push({
proxy: (init as { proxy?: unknown } | undefined)?.proxy,
authorization: headers.get("authorization"),
account: headers.get("chatgpt-account-id"),
body: typeof init?.body === "string" ? JSON.parse(init.body) : undefined,
});
return Response.json({ encrypted_output: "ciphertext", output: "search result" });
}) as typeof fetch;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Search tests check the proxy option, not the network path

The stub confirms which proxy option search passes to fetch, not which route Bun uses. The PR reports no runtime checks. Run the focused search tests and use the loopback proxy tests as a model for verifying the physical route.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

luvs01 commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

Closing this fork PR as superseded by lidge-jun#9129 at 41339b31a7e8. The upstream implementation uses the selected account’s network route for search. Tests cover route selection, refusal before dispatch, and preservation of account health. The upstream PR is open and remains the review target.

@luvs01 luvs01 closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant